{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Connecting to hello world server…\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Exception ignored in: <function Context.__del__ at 0x7f52aaab3060>\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/husheng/local/lib/python3.11/site-packages/zmq/sugar/context.py\", line 151, in __del__\n",
      "    self.destroy()\n",
      "  File \"/home/husheng/local/lib/python3.11/site-packages/zmq/sugar/context.py\", line 333, in destroy\n",
      "    self.term()\n",
      "  File \"/home/husheng/local/lib/python3.11/site-packages/zmq/sugar/context.py\", line 275, in term\n",
      "    super().term()\n",
      "  File \"zmq/backend/cython/context.pyx\", line 83, in zmq.backend.cython.context.Context.term\n",
      "  File \"zmq/backend/cython/checkrc.pxd\", line 13, in zmq.backend.cython.checkrc._check_rc\n",
      "KeyboardInterrupt: \n"
     ]
    }
   ],
   "source": [
    "#client.py\n",
    "\n",
    "import zmq\n",
    "\n",
    "context = zmq.Context()\n",
    "\n",
    "#  Socket to talk to server\n",
    "print(\"Connecting to hello world server…\")\n",
    "socket = context.socket(zmq.REQ)\n",
    "socket.connect(\"tcp://localhost:5555\")\n",
    "socket.send(b\"Hello\")\n",
    "#  Get the reply.\n",
    "message = socket.recv()\n",
    "print(f\"Received reply [ {message} ]\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Received request: b'Hello'\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb Cell 2\u001b[0m line \u001b[0;36m1\n\u001b[1;32m      <a href='vscode-notebook-cell://ssh-remote%2B192.168.12.171/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb#W2sdnNjb2RlLXJlbW90ZQ%3D%3D?line=6'>7</a>\u001b[0m socket\u001b[39m.\u001b[39mbind(\u001b[39m\"\u001b[39m\u001b[39mtcp://*:5555\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m      <a href='vscode-notebook-cell://ssh-remote%2B192.168.12.171/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb#W2sdnNjb2RlLXJlbW90ZQ%3D%3D?line=8'>9</a>\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[1;32m     <a href='vscode-notebook-cell://ssh-remote%2B192.168.12.171/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb#W2sdnNjb2RlLXJlbW90ZQ%3D%3D?line=9'>10</a>\u001b[0m     \u001b[39m#  Wait for next request from client\u001b[39;00m\n\u001b[0;32m---> <a href='vscode-notebook-cell://ssh-remote%2B192.168.12.171/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb#W2sdnNjb2RlLXJlbW90ZQ%3D%3D?line=10'>11</a>\u001b[0m     message \u001b[39m=\u001b[39m socket\u001b[39m.\u001b[39;49mrecv()\n\u001b[1;32m     <a href='vscode-notebook-cell://ssh-remote%2B192.168.12.171/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb#W2sdnNjb2RlLXJlbW90ZQ%3D%3D?line=11'>12</a>\u001b[0m     \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mReceived request: \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m\"\u001b[39m \u001b[39m%\u001b[39m message)\n\u001b[1;32m     <a href='vscode-notebook-cell://ssh-remote%2B192.168.12.171/home/husheng/mywork/notes/python/pyzmq/pyzmp.ipynb#W2sdnNjb2RlLXJlbW90ZQ%3D%3D?line=13'>14</a>\u001b[0m     \u001b[39m#  Do some 'work'\u001b[39;00m\n",
      "File \u001b[0;32mzmq/backend/cython/socket.pyx:805\u001b[0m, in \u001b[0;36mzmq.backend.cython.socket.Socket.recv\u001b[0;34m()\u001b[0m\n",
      "File \u001b[0;32mzmq/backend/cython/socket.pyx:841\u001b[0m, in \u001b[0;36mzmq.backend.cython.socket.Socket.recv\u001b[0;34m()\u001b[0m\n",
      "File \u001b[0;32mzmq/backend/cython/socket.pyx:194\u001b[0m, in \u001b[0;36mzmq.backend.cython.socket._recv_copy\u001b[0;34m()\u001b[0m\n",
      "File \u001b[0;32m~/local/lib/python3.11/site-packages/zmq/backend/cython/checkrc.pxd:13\u001b[0m, in \u001b[0;36mzmq.backend.cython.checkrc._check_rc\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "#server.py\n",
    "import time\n",
    "import zmq\n",
    "\n",
    "context = zmq.Context()\n",
    "socket = context.socket(zmq.REP)\n",
    "socket.bind(\"tcp://*:5555\")\n",
    "\n",
    "while True:\n",
    "    #  Wait for next request from client\n",
    "    message = socket.recv()\n",
    "    print(\"Received request: %s\" % message)\n",
    "\n",
    "    #  Do some 'work'\n",
    "    time.sleep(1)\n",
    "\n",
    "    #  Send reply back to client\n",
    "    socket.send(b\"World\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "--input taxonomy_rarefy-B.txt --mapfile B-group.txt --anova 0.05 --wilcoxon 0.05 --color micro --bar_title_font_size 12 --feature_font_size 7 --bar_class_legend_font_size 8 --width 10 --left_space 0.35 --right_space 0.25 --title Cladogram --title_font_size 10 --cladogram_height 9 --cladogram_width 12 --label_font_size 5 --class_legend_font_size 5 --labeled_start_lev 门 --labeled_stop_lev 属 --abrv_start_lev 门 --abrv_stop_lev 属 --left_space_prop 0.25 --right_space_prop 0.25 --format pdf --dpi 300 --ambiguous no --feature_family normal --legend_family normal --head 0.75'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
